$(function () {
    $.main.init()
});
$.main = {
    vote_status: "0",
    vote_rule: null,
    vote_num: 0,
    user_joinstatus: "0",
    user_votednum: 0,
    user_attention: parseInt(user_attention),
    user_check: 0,
    user_submitinfo: null,
    home_Scroll: null,
    rank_Scroll: null,
    sign_Scroll: null,
    activity_Scroll: null,
    detail_Scroll: null,
    curPage: 0,
    isAnimating: false,
    endCurrPage: false,
    endNextPage: false,
    support: null,
    animEndEventName: null,
    homeData: [],
    homePage: 0,
    rankData: [],
    rankPage: 0,
    detailID: 0,
    searchstatus: false,
    searchData: [],
    searchPaga: 0,
    IsIos: false,
    Is_need_reply: 0,
    wechatjsapi: null,
    init: function () {
      
        var c = this;
        document.addEventListener("touchmove",
        function (d) {
            d.preventDefault()
        },
        false);
        document.addEventListener("DOMContentLoaded", c.loadedFun(), false);
        var a = navigator.userAgent,
        b = navigator.appVersion;
        c.IsIos = !!a.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
        c.shareFun();
        alert(11);
        return;
        $.ajax({
            url: "getdata.ashx?mycat=scrollItem",
            type: "get",
            dataType: "json",
            data: {
                actid: 4
            },
            beforeSend: function () {
                $.showloading.show()
            },
            success: function (e) {
                
                if (e.ret == "0") {
                    var f = e.info.limit == "all" ? e.rank.length : parseInt(e.info.limit);
                    c.rankData = e.rank.slice(0, f);
                    if (parseInt(e.info.rank_type) == 0 || e.list.length <= 0) {
                        var g = [];
                        for (var d = 0; d < e.rank.length; d++) {
                            g.push(e.rank[d])
                        }
                        c.homeData = c.getRndArray(g)
                    } else {
                        c.homeData = e.list
                    }
                    c.vote_status = e.status;
                    c.vote_rule = e.info.vote_rule;
                    c.vote_num = e.info.vote_num,
                    c.user_joinstatus = parseInt(e.user_info.status);
                    c.user_votednum = e.user_info.voted_num;
                    c.user_check = e.info.check;
                    c.Is_need_reply = parseInt(e.info.need_reply);
                    $("#activity_rule").html(e.info.activity_rule);
                    $(".sign-rule p").html(e.user_info.user_info);
                    $("#keyword").html(e.info.keyword);
                    $("#join_num").html(e.info.join_num);
                    $("#vote_num").html(e.info.vote_num_total);
                    $("#pv_num").html(e.info.pv_num);
                    if (c.sign_Scroll == null) {
                        window.location.reload()
                    }
                    c.activity_Scroll.refresh();
                    c.signInfoHtml(e.content)
                } else {
                    $.showstatus.show("接口数据错误！", 1000)
                }
            },
            complete: function () {
                c.homeHtml(c.homePage, false);
                c.rankHtml(c.rankPage);
                setTimeout(function () {
                    var h = c.getQueryString("option");
                    if (h) {
                        c.detailID = h;
                        c.getDetail(false);
                        setTimeout(function () {
                            $.showloading.close();
                            c.pageCutFun(4, c.animEndEventName)
                        },
                        800)
                    } else {
                        $.showloading.close()
                    }
                },
                1000);
                $("#vote-search").on("click",
                function (j) {
                    var l = $(this).hasClass("cancel"),
                    k = $("#vote-searchval").val(),
                    p = 0;
                    $("#vote-list ul.col").html("");
                    c.homePage = 0;
                    for (var n = 0; n < c.homeData.length; n++) {
                        var q = c.homeData[n].name,
                        m = c.homeData[n].number,
                        o = q.indexOf(k),
                        h = m.indexOf(k);
                        if (o != -1 || h != -1) {
                            c.searchData[p] = c.homeData[n];
                            p++
                        }
                    }
                    if (l) {
                        $(this).html("搜索").removeClass("cancel");
                        $("#vote-searchval").val("");
                        c.searchstatus = false;
                        c.homeHtml(c.homePage, c.searchstatus)
                    } else {
                        $(this).html("取消").addClass("cancel");
                        c.searchstatus = true;
                        c.homeHtml(c.searchPaga, c.searchstatus)
                    }
                });
                $("#sign_but").on("click",
                function (h) {
                    if (c.user_attention == 0) {
                        c.signUpFun()
                    } else {
                        window.location.href = "/vote2/code/?id=" + voteID
                    }
                });
                $("#sign-successBut").on("click",
                function (i) {
                    c.signInfoHtml(c.user_submitinfo);
                    if (c.user_check != "1") {
                        var h = '<li class="vote-item"><a class="goto-detail" data-id="' + c.user_submitinfo.id + '" href="javascript:;"><img src="' + c.user_submitinfo.photo[0] + '" /></a><p class="name">' + c.user_submitinfo.name + '</p><p class="code clearfix"><span class="fl">编号:' + c.user_submitinfo.number + '</span><span class="fr"><b>' + c.user_submitinfo.poll + '</b>票</span></p><p><a class="but default vote-totabut issign" data-id="' + c.user_submitinfo.id + '" href="javascript:;">投TA一票</a></p></li>';
                        $("#vote-list ul.col").eq(0).find("li").eq(0).before(h);
                        c.bindEvent();
                        $.showloading.show();
                        c.detailID = c.user_submitinfo.id;
                        c.getDetail(true);
                        setTimeout(function () {
                            $.showloading.close();
                            c.pageCutFun(4, c.animEndEventName)
                        },
                        800)
                    }
                    $(".showbox-bg,.sign-success").hide()
                });
                $("#sign-againbut").on("click",
                function (h) {
                    c.user_joinstatus = 0;
                    c.signInfoHtml();
                    c.sign_Scroll.refresh()
                });
                $("#detail-votebut").on("click",
                function (h) {
                    var i = $(this).attr("data-id");
                    c.voteAjax(voteID, i)
                });
                $("#detail-gosign").on("click",
                function (h) {
                    if (c.user_attention == 0) {
                        $.showloading.show();
                        setTimeout(function () {
                            $.showloading.close();
                            c.pageCutFun(2, c.animEndEventName)
                        },
                        800)
                    } else {
                        window.location.href = "/vote2/code/?id=" + voteID
                    }
                });
                $(".onekey-Focus .close").click(function (h) {
                    $(".onekey-Focus,.showbox-bg").hide()
                });
                var g = window.innerWidth / 320;
                $(".swiper-container").css("height", 160 * g);
                var d = new Swiper("#swiper-home", {
                    autoplay: 3000,
                    loop: true,
                    pagination: "#swiper-home .swiper-pagination"
                });
                var f = new Swiper("#swiper-sign", {
                    autoplay: 3000,
                    loop: true,
                    pagination: "#swiper-sign .swiper-pagination"
                });
                var e = new Swiper("#swiper-activity", {
                    autoplay: 3000,
                    loop: true,
                    pagination: "#swiper-activity .swiper-pagination"
                });
                c.pageCut();
                setTimeout(function () {
                    $.showloading.close()
                },
                1000)
            }
        })
    },
    loadedFun: function () {
        var a = this;
        setTimeout(function () {
            a.pullUpFunHome();
            a.pullUpFunRank();
            a.sign_Scroll = new iScroll("sign-scroll", {
                mouseWheel: true
            });
            a.activity_Scroll = new iScroll("activity-scroll", {
                mouseWheel: true
            });
            a.detail_Scroll = new iScroll("detail-scroll", {
                mouseWheel: true
            })
        },
        100)
    },
    getQueryString: function (a) {
        var b = new RegExp("(^|&)" + a + "=([^&]*)(&|$)", "i");
        var c = window.location.search.substr(1).match(b);
        if (c != null) {
            return unescape(c[2])
        }
        return null
    },
    bindEvent: function () {
        var a = this;
        $(".goto-detail").off("click").on("click",
        function (e) {
            $.showloading.show();
            var g = $(this).attr("data-id"),
            c = $(this).hasClass("issign");
            a.detailID = g;
            a.detail_Scroll.scrollTo(0, 0);
            if (a.detailID != "") {
                if (c) {
                    a.getDetail(true)
                } else {
                    a.getDetail(false)
                }
                var f = $("body").attr("weiba-link");
                var d = f.split("&");
                var b = d[0] + "&option=" + g;
                setTimeout(function () {
                    $("body").attr("weiba-link", b);
                    a.shareChangeUrl();
                    $.showloading.close();
                    a.pageCutFun(4, a.animEndEventName)
                },
                800)
            }
        });
        $(".vote-totabut").off("click").on("click",
        function (b) {
            var c = $(this).attr("data-id");
            if (a.Is_need_reply == 1) {
                if (a.user_attention == 0) {
                    if (a.vote_status == 0) {
                        a.voteAjax(voteID, c)
                    } else {
                        if (a.vote_status == 2) {
                            $.showstatus.show("活动未开始！", 2000)
                        } else {
                            if (a.vote_status == 1) {
                                $.showstatus.show("活动已经结束啦！", 2000)
                            }
                        }
                    }
                } else {
                    window.location.href = "/vote2/code/?id=" + voteID
                }
            } else {
                if (a.vote_status == 2) {
                    $.showstatus.show("活动未开始！", 2000);
                    return
                } else {
                    if (a.vote_status == 1) {
                        $.showstatus.show("活动已经结束啦！", 2000);
                        return
                    }
                }
                a.voteAjax(voteID, c)
            }
        })
    },
    pageCut: function () {
        var b = this,
        a = {
            WebkitAnimation: "webkitAnimationEnd",
            OAnimation: "oAnimationEnd",
            msAnimation: "MSAnimationEnd",
            animation: "animationend"
        };
        b.animEndEventName = a[Modernizr.prefixed("animation")];
        b.support = Modernizr.cssanimations;
        $(".main .page").eq(b.curPage).addClass("cur");
        $(".main .page").each(function (d, e) {
            var c = $(this);
            c.data("originalClassList", "page")
        });
        $(".bar a").on("click",
        function (h) {
            var f = $(this).index(),
            c = $(".bar a").size(),
            g = $(this).attr("data-type");
            var i = $("body").attr("weiba-link");
            var e = i.split("&");
            var d = e[0];
            $("body").attr("weiba-link", d);
            b.shareChangeUrl();
            if (c == 3 && f == 2) {
                f = 3;
                b.activity_Scroll.refresh()
            } else {
                if (c == 4 && f == 3) {
                    b.activity_Scroll.refresh()
                }
            }
            if (g == "sign") {
                if (c == 4 && f == 2) {
                    if (b.user_attention == 0) {
                        b.signInfoFun()
                    } else {
                        window.location.href = "/vote2/code/?id=" + voteID
                    }
                }
            } else {
                b.pageCutFun(f, b.animEndEventName)
            }
        });
        b.bindEvent()
    },
    pageCutFun: function (i, g) {
        var h = this,
        m = i,
        n = g,
        l = h.curPage,
        a = h.isAnimating;
        if (m != l && a == false) {
            h.isAnimating = true;
            var b = $(".main .page").eq(l),
            f = $(".main .page").eq(m).addClass("cur"),
            e = "",
            k = "";
            if (m > l) {
                e = "page-fade";
                k = "page-moveFromRight page-ontop"
            }
            if (m < l) {
                e = "page-fade";
                k = "page-moveFromLeft page-ontop"
            }
            b.addClass(e).on(n,
            function () {
                b.off(n);
                h.endCurrPage = true;
                if (h.endNextPage) {
                    j(b, f);
                    h.curPage = m
                }
            });
            f.addClass(k).on(n,
            function () {
                f.off(n);
                h.endNextPage = true;
                if (h.endCurrPage) {
                    j(b, f);
                    h.curPage = m
                }
            });
            if (m < 4) {
                var d = m;
                if (IS_closeSign == true && i == 3) {
                    d = 2
                }
                $(".bar a").eq(d).addClass("cur").siblings("a").removeClass("cur")
            }
            if (!h.support) {
                j(b, f)
            }
        }
        function j(p, o) {
            h.endCurrPage = false;
            h.endNextPage = false;
            c(p, o);
            h.isAnimating = false
        }
        function c(p, o) {
            p.attr("class", p.data("originalClassList"));
            o.attr("class", o.data("originalClassList") + " cur")
        }
    },
    getRndArray: function (b) {
        var d = new Array(),
        a = b.length;
        for (var c = 0; c < a; c++) {
            rnd = Math.floor(Math.random() * b.length);
            d[c] = b[rnd];
            b.splice(rnd, 1)
        }
        return d
    },
    homeHtml: function (l, c) {
        var k = this,
        e = [],
        m = 0,
        n = 0,
        h = 0;
        if (c) {
            e = k.searchData
        } else {
            e = k.homeData
        }
        m = e.length;
        if (l == 0) {
            n = 0;
            h = 20
        } else {
            n = 20 + (l - 1) * 10;
            h = 20 + l * 10
        }
        if (h >= m) {
            h = m;
            $("#vote-pullUp").hide()
        }
        for (var f = n; f < h; f++) {
            var g = "",
            b = e[f].id,
            a = e[f].photo[0],
            d = e[f].name,
            j = e[f].number,
            o = e[f].poll;
            g = '<li class="vote-item" data-id="' + b + '"><a class="goto-detail" data-id="' + b + '" href="javascript:;"><img src="' + a + '" onload="$.main.home_Scroll.refresh();" /></a><p class="name">' + d + '</p><p class="code clearfix"><span class="fl">编号:' + j + '</span><span class="fr"><b class="vote-pollsum">' + o + '</b>票</span></p><p><a class="but default vote-totabut" data-id="' + b + '" href="javascript:;">投TA一票</a></p></li>';
            if (f % 2 == 0) {
                $("#vote-list ul.col").eq(0).append(g)
            } else {
                $("#vote-list ul.col").eq(1).append(g)
            }
        }
        if (m == 0) {
            $("#vote-list").html('<p style="height:100px;line-height:100px;font-size: 24px;color: #333;text-align: center;">暂无选项</p>')
        }
        k.bindEvent();
        setTimeout(function () {
            k.home_Scroll.refresh()
        },
        1000)
    },
    pullUpFunHome: function () {
        var c = this,
        b = document.getElementById("vote-pullUp"),
        a = b.offsetHeight;
        c.home_Scroll = new iScroll("home-scroll", {
            onRefresh: function () {
                if (b.className.match("loading")) {
                    b.className = "";
                    b.querySelector(".vote-pullUptext").innerHTML = "上拉加载更多..."
                }
            },
            onScrollMove: function () {
                if (this.y < (this.maxScrollY - 5) && !b.className.match("flip")) {
                    b.className = "flip";
                    b.querySelector(".vote-pullUptext").innerHTML = "松手开始更新...";
                    this.maxScrollY = this.maxScrollY
                } else {
                    if (this.y > (this.maxScrollY + 5) && b.className.match("flip")) {
                        b.className = "";
                        b.querySelector(".vote-pullUptext").innerHTML = "上拉加载更多...";
                        this.maxScrollY = a
                    }
                }
            },
            onScrollEnd: function () {
                if (b.className.match("flip")) {
                    b.className = "loading";
                    b.querySelector(".vote-pullUptext").innerHTML = "加载中...";
                    if (c.searchstatus) {
                        c.searchPaga++;
                        c.homeHtml(c.searchPaga, c.searchstatus)
                    } else {
                        c.homePage++;
                        c.homeHtml(c.homePage, c.searchstatus)
                    }
                }
            }
        })
    },
    getMinUl: function () {
        var c = null,
        b = $("#vote-list ul.col").eq(0).height(),
        a = $("#vote-list ul.col").eq(1).height();
        if (b > a) {
            c = $("#vote-list ul.col").eq(1)
        } else {
            c = $("#vote-list ul.col").eq(0)
        }
        return c
    },
    rankHtml: function (d) {
        var g = this,
        a = g.rankData.length,
        f, e, c = "";
        if (d == 0) {
            f = 0;
            e = 20
        } else {
            f = 20 + (d - 1) * 10;
            e = 20 + d * 10
        }
        if (e > a) {
            e = a;
            $("#rank-pullUp").hide()
        }
        for (var b = f; b < e; b++) {
            self_id = g.rankData[b].id,
            self_rank = g.rankData[b].rank,
            self_img = g.rankData[b].photo[0],
            self_name = g.rankData[b].name,
            self_nub = g.rankData[b].number,
            self_poll = g.rankData[b].poll;
            c += '<li class="rank-item box" data-id="' + self_id + '"><div class="rank-img"><span>' + self_rank + '</span><a class="goto-detail" data-id="' + self_id + '" href="javascript:;"><img src="' + self_img + '" onload="$.main.rank_Scroll.refresh();" /></a></div><div class="rank-info boxflex"><p class="name">' + self_name + '</p><p class="code clearfix"><span class="fl">编号:' + self_nub + '</span><span class="fr"><b class="vote-pollsum">' + self_poll + '</b>票</span></p><p><a class="but default vote-totabut" data-id="' + self_id + '" href="javascript:;">投TA一票</a></p></div></li>'
        }
        $("#rank-list").append(c);
        if (a == 0) {
            $(".rank-con").html('<p style="height:100px;line-height:100px;font-size: 24px;color: #333;text-align: center;">暂无选项</p>');
            $("#vote-pullUp").hide()
        }
        g.bindEvent()
    },
    pullUpFunRank: function () {
        var c = this,
        b = document.getElementById("rank-pullUp"),
        a = b.offsetHeight;
        c.rank_Scroll = new iScroll("rank-scroll", {
            onRefresh: function () {
                if (b.className.match("loading")) {
                    b.className = "";
                    b.querySelector(".rank-pullUptext").innerHTML = "上拉加载更多..."
                }
            },
            onScrollMove: function () {
                if (this.y < (this.maxScrollY - 5) && !b.className.match("flip")) {
                    b.className = "flip";
                    b.querySelector(".rank-pullUptext").innerHTML = "松手开始更新...";
                    this.maxScrollY = this.maxScrollY
                } else {
                    if (this.y > (this.maxScrollY + 5) && b.className.match("flip")) {
                        b.className = "";
                        b.querySelector(".rank-pullUptext").innerHTML = "上拉加载更多...";
                        this.maxScrollY = a
                    }
                }
            },
            onScrollEnd: function () {
                if (b.className.match("flip")) {
                    b.className = "loading";
                    b.querySelector(".rank-pullUptext").innerHTML = "加载中...";
                    c.homePage++;
                    c.rankHtml(c.homePage);
                    this.refresh()
                }
            }
        })
    },
    getDetail: function (e) {
        var d = this,
        a = parseInt(d.detailID);
        if (e) {
            var c = d.user_submitinfo;
            $("#detail-number").html("编号：" + c.number);
            $("#detail-name").html(c.name);
            $("#detail-poll").html(c.poll + "票");
            $("#detail-rank").html(c.rank + "名");
            $("#detail-diff").html(c.difference + "票");
            var b = "";
            $(c.photo).each(function (f, g) {
                b += '<p><img src="' + this + '" onload="$.main.detail_Scroll.refresh();" /></p>'
            });
            b += '<div class="detail-info"><div class="detail-info-con">' + c.recommend + "</div></div>";
            $("#detail-votebut").attr("data-id", a);
            $("#detail-con").html(b)
        } else {
            if (a != "") {
                $(d.homeData).each(function (f, h) {
                    if (a == parseInt(this.id)) {
                        console.log("sss", this.rank);
                        $("#detail-number").html("编号：" + this.number);
                        $("#detail-name").html(this.name);
                        $("#detail-poll").html(this.poll + "票");
                        $("#detail-rank").html(this.rank + "名");
                        $("#detail-diff").html(this.difference + "票");
                        var g = "";
                        $(this.photo).each(function (i, j) {
                            g += '<p><img src="' + this + '" onload="$.main.detail_Scroll.refresh();" /></p>'
                        });
                        g += '<div class="detail-info"><div class="detail-info-con">' + this.recommend + "</div></div>";
                        $("#detail-votebut").attr("data-id", a);
                        $("#detail-con").html(g)
                    }
                })
            }
        }
    },
    voteAjax: function (b, a) {
        var c = this;
        if (c.user_votednum < c.vote_num) {
            $.ajax({
                url: "/data/vote2/mvote",
                type: "get",
                dataType: "json",
                data: {
                    id: b,
                    option_id: a
                },
                beforeSend: function () {
                    $.showloading.show()
                },
                success: function (d) {
                    if (d.status == "0") {
                        $.showstatus.show("投票成功！", 1000);
                        c.user_votednum++;
                        console.log("请求成功", c.user_votednum);
                        c.editData(a)
                    } else {
                        $.showstatus.show(d.msg, 1000);
                        return false
                    }
                },
                complete: function () {
                    $.showloading.close()
                }
            })
        } else {
            if (c.vote_rule == "0") {
                $.showstatus.show("每人每天只能投" + c.vote_num + "票！明天再来吧！", 1000)
            }
            if (c.vote_rule == "1") {
                $.showstatus.show("每人只能投" + c.vote_num + "票,谢谢参与！", 1000)
            }
        }
    },
    editData: function (a) {
        var b = this;
        $("#vote-list ul").each(function (c, d) {
            $(this).find("li").each(function (e, f) {
                var h = $(this).attr("data-id"),
                g = parseInt($(this).find(".vote-pollsum").html());
                if (a == h) {
                    $(this).find(".vote-pollsum").html(g + 1)
                }
            })
        });
        $(b.homeData).each(function (c, d) {
            var f = this.id;
            if (a == f) {
                var e = parseInt(this.poll);
                this.poll = (e)
            }
        });
        $("#rank-list li").each(function (c, d) {
            var f = $(this).attr("data-id"),
            e = parseInt($(this).find(".vote-pollsum").html());
            if (a == f) {
                $(this).find(".vote-pollsum").html(e + 1)
            }
        });
        $(b.rankData).each(function (c, d) {
            var f = this.id,
            e = parseInt(this.poll);
            if (a == f) {
                this.poll = e + 1
            }
        })
    },
    signUpFun: function () {
        var h = this,
        g = $(".sign-votetitle").val(),
        e = $(".sign-voteinfo").val(),
        c = $(".sign-votename").val(),
        b = $(".sign-votetel").val(),
        d = [],
        f = false;
        $(".sign-uploadimg .imgbox").each(function (i, j) {
            var k = $(this).find("img").attr("src");
            d.push(k)
        });
        if (g != "" && e != "" && c != "" && b != "" && d.length > 0) {
            var a = /^[0-9]*$/;
            if (!a.exec(b)) {
                f = false;
                $.showstatus.show("请填写正确的手机号码", 1000)
            } else {
                f = true
            }
        } else {
            if (g == "") {
                $.showstatus.show("标题不能为空", 1000)
            } else {
                if (e == "") {
                    $.showstatus.show("介绍不能为空", 1000)
                } else {
                    if (c == "") {
                        $.showstatus.show("联系人姓名不能为空", 1000)
                    } else {
                        if (b == "") {
                            $.showstatus.show("联系人手机不能为空", 1000)
                        } else {
                            if (d.length == 0) {
                                $.showstatus.show("请上传至少一张图片", 1000)
                            }
                        }
                    }
                }
            }
        }
        if (f) {
            $.ajax({
                url: "/data/vote2/mjoin",
                type: "POST",
                dataType: "json",
                data: {
                    title: g,
                    intro: e,
                    img: d,
                    tel: b,
                    name: c,
                    vote_id: voteID
                },
                beforeSend: function () {
                    $.showloading.show()
                },
                success: function (i) {
                    if (i.ret == 0) {
                        $(".showbox-bg,.sign-success").show();
                        h.user_submitinfo = i.data[0];
                        h.user_joinstatus = parseInt(i.status)
                    } else {
                        $.showstatus.show(i.msg, 1000)
                    }
                },
                complete: function () {
                    $.showloading.close()
                }
            })
        }
    },
    signInfoFun: function () {
        var a = this;
        $.ajax({
            url: "/data/vote2/userJoinStatus",
            type: "GET",
            dataType: "json",
            data: {
                id: voteID
            },
            beforeSend: function () {
                $.showloading.show()
            },
            success: function (b) {
                if (b.ret == "0") {
                    a.user_joinstatus = parseInt(b.status);
                    a.signInfoHtml(b.data);
                    a.pageCutFun(2, a.animEndEventName)
                } else { }
            },
            complete: function () {
                $.showloading.close()
            }
        })
    },
    signInfoHtml: function (b) {
        var d = this,
        a = b,
        c = "";
        if (d.vote_status == "0") {
            switch (d.user_joinstatus) {
                case 0:
                    $(".sign-con .sign-fail").hide();
                    $(".sign-con .sign-right").hide();
                    $(".sign-con .vote-over").hide();
                    $(".sign-con .sign-from").show();
                    d.uploadImg();
                    break;
                case 1:
                    $(".sign-con .sign-from").hide();
                    $(".sign-con .sign-fail").hide();
                    $(".sign-con .vote-over").hide();
                    $(".sign-right .info").hide();
                    $("#detail-gosign").parent().hide();
                    c = '<div class="detail-con"><p class="detail-title"><i></i><span>编号：' + a.number + '</span></p><p class="detail-name">' + a.name + '</p><div class="detail-rank box"><div class="detail-rank-c boxflex"><span class="t">当前票数</span><span class="c">' + a.poll + '票</span></div><div class="detail-rank-c boxflex"><span class="t">当前排名</span><span class="c">' + a.rank + '名</span></div></div><p class="detail-diff">离上一名还差<span>' + a.difference + '票</span>啊，朋友们快帮我投票啊</p><div class="detail-box">';
                    $(a.photo).each(function (e, f) {
                        c += '<p><img src="' + this + '" onload="$.main.sign_Scroll.refresh();"></p>'
                    });
                    c += '<div class="detail-info"><div class="detail-info-con">' + a.recommend + "</div></div></div></div>";
                    $(".sign-right").show();
                    $(".sign-right .sign-right-user").html(c);
                    break;
                case 2:
                    $(".sign-con .sign-from").hide();
                    $(".sign-con .sign-right").hide();
                    $(".sign-con .vote-over").hide();
                    $(".sign-fail").show();
                    break;
                case 3:
                    $(".sign-con .sign-from").hide();
                    $(".sign-con .sign-fail").hide();
                    $(".sign-con .vote-over").hide();
                    $("#detail-gosign").parent().hide();
                    c = '<div class="detail-box">';
                    $(a.photo).each(function (e, f) {
                        c += '<p><img src="' + this + '" onload="$.main.sign_Scroll.refresh();"></p>'
                    });
                    c += '<div class="detail-info"><div class="detail-info-con">' + a.recommend + "</div></div></div></div>";
                    $(".sign-right").show();
                    $(".sign-right .sign-right-user").html(c);
                    break
            }
        } else {
            if (d.vote_status == "1") {
                $(".sign-from,.sign-right,.sign-fail").hide();
                $("#detail-gosign").parent().hide();
                $(".vote-over").show()
            } else {
                if (d.vote_status == "2") {
                    $(".sign-from,.sign-right,.sign-fail").hide();
                    $("#detail-gosign").parent().hide();
                    $(".vote-notbegin").show()
                }
            }
        }
        d.sign_Scroll.refresh()
    },
    uploadImg: function () {
        var f = this,
        b = 0;
        var e = $(".file_but");
        $(".file_but").off("change").on("change",
        function () {
            var h = $(this).get(0).files[0];
            if (h.size >= 3 * 1024 * 1024) {
                $.showstatus.show('您传的这张"' + h.name + '"图片，大小超过3M', 2000)
            } else {
                $.showloading.show();
                if (f.IsIos) {
                    EXIF.getData(h,
                    function () {
                        var i = EXIF.getTag(this, "Orientation");
                        var j = document.getElementById("mycanvas");
                        var k = new MegaPixImage(h);
                        k.render(j, {
                            maxWidth: 1000,
                            maxHeight: 1500,
                            orientation: i
                        });
                        setTimeout(function () {
                            var l = j.toDataURL("image/jpeg", 1);
                            c(l)
                        },
                        1000)
                    })
                } else {
                    var g = new FileReader();
                    g.readAsDataURL(h);
                    g.onload = function (i) {
                        var j = i.target.result;
                        if (a(j)) {
                            c(j)
                        } else {
                            $.showstatus.show("我们只支持PNG,JPG上传", 1000)
                        }
                    }
                }
            }
        });
        function c(g) {
            $.post("/data/image/upload_gd", {
                image: g
            },
            function (h) {
                $.showloading.close();
                if (h && h.ret == 0) {
                    e.val("");
                    var i = '<span class="imgbox"><img src="' + h.data.middle_img + '" width="60" height="60" /><a class="del upload_imgdel" href="javascript:;">删除</a></span>';
                    e.parent().before(i);
                    d();
                    f.sign_Scroll.refresh()
                } else {
                    $.showstatus.show(h.message, 1000)
                }
            },
            "json")
        }
        function a(h) {
            var g = {
                jpg: "/9j/4",
                png: "iVBORw"
            };
            var j = h.indexOf(",") + 1;
            for (var i in g) {
                if (h.indexOf(g[i]) === j) {
                    return i
                }
            }
            return null
        }
        function d() {
            $(".upload_imgdel").off("click").click(function (g) {
                $(this).parent().remove();
                return false
            })
        }
    },
    shareFun: function () {
        var a = this;
        $.getJSON("/data/wechatjsapi", {
            url: window.location.href
        },
        function (b) {
            if (b && b.ret == 0 && b.data) {
                var c = b.data;
                if (wx && wx.ready) {
                    wx.config({
                        debug: false,
                        appId: c.appId,
                        timestamp: c.timestamp,
                        nonceStr: c.nonceStr,
                        signature: c.signature,
                        jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage"]
                    });
                    a.shareChangeUrl()
                }
            }
        })
    },
    shareChangeUrl: function () {
        var d = $("body").attr("weiba-title"),
        c = $("body").attr("weiba-desc"),
        b = $("body").attr("weiba-link"),
        a = $("body").attr("weiba-icon");
        wx.ready(function () {
            wx.onMenuShareTimeline({
                title: d,
                desc: c,
                link: b,
                imgUrl: a
            });
            wx.onMenuShareAppMessage({
                title: d,
                desc: c,
                link: b,
                imgUrl: a
            })
        })
    }
};
$.showloading = {
    htmls: function () {
        var a = '<div class="showloading-bg"></div><div class="showloading"><span></span></div>';
        $("body").append(a)
    },
    show: function () {
        var a = this;
        a.htmls();
        $(".showloading-bg").css("display", "block");
        $(".showloading").css("display", "block")
    },
    close: function () {
        $(".showloading-bg").remove();
        $(".showloading").remove()
    }
};
$.showstatus = {
    show: function (e, d) {
        var c = '<div class="showtatus">' + e + "</div>";
        $("body").append(c);
        $(".showtatus").css("display", "block");
        var b = $(".showtatus").width();
        $(".showtatus").css("margin-left", -b / 2 - 12);
        var a = d == "" ? 1000 : d;
        setTimeout(function () {
            $(".showtatus").remove()
        },
        a)
    }
};